package com.ruoyi.jiajia.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.JiajiaPointsFlow;
import com.ruoyi.system.service.IJiajiaPointsFlowService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 项目积分流水Controller
 * 
 * @author ruoyi
 * @date 2025-03-10
 */
@Controller
@RequestMapping("/system/flow")
public class JiajiaPointsFlowController extends BaseController
{
    private String prefix = "system/flow";

    @Autowired
    private IJiajiaPointsFlowService jiajiaPointsFlowService;

    @RequiresPermissions("system:flow:view")
    @GetMapping()
    public String flow()
    {
        return prefix + "/flow";
    }

    /**
     * 查询项目积分流水列表
     */
    @RequiresPermissions("system:flow:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaPointsFlow jiajiaPointsFlow)
    {
        startPage();
        List<JiajiaPointsFlow> list = jiajiaPointsFlowService.selectJiajiaPointsFlowList(jiajiaPointsFlow);
        return getDataTable(list);
    }

    /**
     * 导出项目积分流水列表
     */
    @RequiresPermissions("system:flow:export")
    @Log(title = "项目积分流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaPointsFlow jiajiaPointsFlow)
    {
        List<JiajiaPointsFlow> list = jiajiaPointsFlowService.selectJiajiaPointsFlowList(jiajiaPointsFlow);
        ExcelUtil<JiajiaPointsFlow> util = new ExcelUtil<JiajiaPointsFlow>(JiajiaPointsFlow.class);
        return util.exportExcel(list, "项目积分流水数据");
    }

    /**
     * 新增项目积分流水
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存项目积分流水
     */
    @RequiresPermissions("system:flow:add")
    @Log(title = "项目积分流水", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaPointsFlow jiajiaPointsFlow)
    {
        return toAjax(jiajiaPointsFlowService.insertJiajiaPointsFlow(jiajiaPointsFlow));
    }

    /**
     * 修改项目积分流水
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaPointsFlow jiajiaPointsFlow = jiajiaPointsFlowService.selectJiajiaPointsFlowById(id);
        mmap.put("jiajiaPointsFlow", jiajiaPointsFlow);
        return prefix + "/edit";
    }

    /**
     * 修改保存项目积分流水
     */
    @RequiresPermissions("system:flow:edit")
    @Log(title = "项目积分流水", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaPointsFlow jiajiaPointsFlow)
    {
        return toAjax(jiajiaPointsFlowService.updateJiajiaPointsFlow(jiajiaPointsFlow));
    }

    /**
     * 删除项目积分流水
     */
    @RequiresPermissions("system:flow:remove")
    @Log(title = "项目积分流水", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiajiaPointsFlowService.deleteJiajiaPointsFlowByIds(ids));
    }
}
